package com.jdbc连接;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCDemo {

	public static void main(String[] args) {

		// reflectdemo();
		try {
			prepareCall();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	
	/**
	 * 存储函数
	 * 
	 * @throws SQLException
	 */
	private static void prepareCall() throws SQLException {
		Connection conn = DBUtil.getConnection();
		// 创建存储过程的对象
		CallableStatement c = conn.prepareCall("{call sp_user()}");
		// 执行存储过程
		c.execute();
		ResultSet rs = c.executeQuery();
		while (rs.next()) {
			int id = rs.getInt(1);
			String username = rs.getString("username");
			System.out.println(id + ", " + username);
		}
		conn.close();
		c.close();
	}

}
